import {require} from '../../../utils/require'
Page({ 
  data: {
    batch:'请输入批次',
    good:0,
    bad:0,
    percentage:0,
    value: ''
  },

  observers:{
    'good,bad'(good,bad){
      this.setData({
        percentage:good/(good+bad)
      })
    }
  },

  onChange(e) { 
    console.log(e.detail)
    this.setData({
      // model:value="{{e.detail}}"
      value:e.detail
    });  
  },
  
  onSearch() {
      return require('/produce/getDataByBatch','post',{
        data:{
          batch:this.data.value
        },
        header:{
          "token":wx.getStorageSync('token'),
          "Content-Type":"application/x-www-form-urlencoded"
        }
      }).then(res=>{
        console.log(res)
        if(res.data.code===200){
          this.setData({
          batch:res.data.obj.batch,
          good:res.data.obj.goodNum,
          bad:res.data.obj.badNum,
          percentage:res.data.obj.qualifyRate
          })
        }else{
          this.setData({
            batch:'批次错误，请重新输入',
            good:0,
            bad:0,
            percentage:0
          })
        }
      });
  },


  
  onClick(){   
    return require('/produce/getDataByBatch','post',{
      data:{
        batch:this.data.value
      },
      header:{
        "token":wx.getStorageSync('token'),
        "Content-Type":"application/x-www-form-urlencoded"
      }
    }).then(res=>{
      console.log(res)
      if(res.data.code===200){
        this.setData({
        batch:res.data.obj.batch,
        good:res.data.obj.goodNum,
        bad:res.data.obj.badNum,
        percentage:res.data.obj.qualifyRate
        })
      }else{
        this.setData({
          batch:'批次错误，请重新输入',
          good:0,
          bad:0,
          percentage:0
        })
      }
    });
    } 
})
